﻿using System;
using System.IO;
using Manager;
using UnityEngine;

namespace Studio
{
	// Token: 0x02000530 RID: 1328
	public class ENVCtrl
	{
		// Token: 0x17000402 RID: 1026
		// (get) Token: 0x060021C7 RID: 8647 RVA: 0x000CDC0C File Offset: 0x000CBE0C
		// (set) Token: 0x060021C8 RID: 8648 RVA: 0x000CDC14 File Offset: 0x000CBE14
		public BGMCtrl.Repeat repeat
		{
			get
			{
				return this.m_Repeat;
			}
			set
			{
				if (Utility.SetStruct<BGMCtrl.Repeat>(ref this.m_Repeat, value) && this.audioSource)
				{
					this.audioSource.loop = (this.repeat == BGMCtrl.Repeat.All);
				}
			}
		}

		// Token: 0x17000403 RID: 1027
		// (get) Token: 0x060021C9 RID: 8649 RVA: 0x000CDC4C File Offset: 0x000CBE4C
		// (set) Token: 0x060021CA RID: 8650 RVA: 0x000CDC54 File Offset: 0x000CBE54
		public int no
		{
			get
			{
				return this.m_No;
			}
			set
			{
				if (this.m_No != value)
				{
					this.Play(value);
				}
			}
		}

		// Token: 0x17000404 RID: 1028
		// (get) Token: 0x060021CB RID: 8651 RVA: 0x000CDC6C File Offset: 0x000CBE6C
		// (set) Token: 0x060021CC RID: 8652 RVA: 0x000CDC74 File Offset: 0x000CBE74
		public bool play
		{
			get
			{
				return this.m_Play;
			}
			set
			{
				if (Utility.SetStruct<bool>(ref this.m_Play, value))
				{
					if (this.m_Play)
					{
						this.Play();
					}
					else
					{
						this.Stop();
					}
				}
			}
		}

		// Token: 0x060021CD RID: 8653 RVA: 0x000CDCA4 File Offset: 0x000CBEA4
		public void Play()
		{
			this.m_Play = true;
			this.Play(this.m_No);
		}

		// Token: 0x060021CE RID: 8654 RVA: 0x000CDCBC File Offset: 0x000CBEBC
		public void Play(int _no)
		{
			this.m_No = _no;
			if (!this.m_Play)
			{
				return;
			}
			Info.LoadCommonInfo loadCommonInfo = null;
			if (!Singleton<Info>.Instance.dicENVLoadInfo.TryGetValue(this.m_No, out loadCommonInfo))
			{
				return;
			}
			Singleton<Manager.Sound>.Instance.Stop(Manager.Sound.Type.ENV);
			Transform transform = Singleton<Manager.Sound>.Instance.Play(Manager.Sound.Type.ENV, loadCommonInfo.bundlePath, loadCommonInfo.fileName, 0f, 0f, true, true, -1, true);
			if (transform == null)
			{
				return;
			}
			this.audioSource = transform.GetComponent<AudioSource>();
			this.audioSource.loop = (this.repeat == BGMCtrl.Repeat.All);
			this.audioSource.spatialBlend = 0f;
		}

		// Token: 0x060021CF RID: 8655 RVA: 0x000CDD6C File Offset: 0x000CBF6C
		public void Stop()
		{
			this.m_Play = false;
			Singleton<Manager.Sound>.Instance.Stop(Manager.Sound.Type.ENV);
		}

		// Token: 0x060021D0 RID: 8656 RVA: 0x000CDD80 File Offset: 0x000CBF80
		public void Save(BinaryWriter _writer, Version _version)
		{
			_writer.Write((int)this.m_Repeat);
			_writer.Write(this.m_No);
			_writer.Write(this.m_Play);
		}

		// Token: 0x060021D1 RID: 8657 RVA: 0x000CDDA8 File Offset: 0x000CBFA8
		public void Load(BinaryReader _reader, Version _version)
		{
			this.m_Repeat = (BGMCtrl.Repeat)_reader.ReadInt32();
			this.m_No = _reader.ReadInt32();
			this.m_Play = _reader.ReadBoolean();
		}

		// Token: 0x04002323 RID: 8995
		private BGMCtrl.Repeat m_Repeat = BGMCtrl.Repeat.All;

		// Token: 0x04002324 RID: 8996
		private int m_No;

		// Token: 0x04002325 RID: 8997
		private bool m_Play;

		// Token: 0x04002326 RID: 8998
		private AudioSource audioSource;
	}
}
